import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import TestResult from '../Component/test/testResult';
import services from 'src/services/api';
import { message } from 'antd';
import StrategyBaseDetail from './strategyBaseDetail';

function StrategyLog(props) {
  const { strategy_id, version, logs, actions, codes, name, comments, variable, using_variables } = props;
  const [value, setValue] = useState({});
  useEffect(() => {
    getDetail(strategy_id, version);
  }, []);

  // 获取详情
  function getDetail(id, version) {
    const params = version ? { id: id, version } : { id: id };
    services.strategyComponent.queryOne(params).then((res) => {
      if (res.code === '0') {
        // res.data.config = JSON.parse(res.data.config);
        setValue(res.data);
      } else {
        message.error(res.msg);
      }
    });
  }
  return (
    <>
      <StrategyBaseDetail
        modes={codes.strategy_mode || []}
        detail={value}
        mode={value.mode || ''}
        name={name}
        disabled={true}
        version={version}
      />
      {comments && <span className='waring-txt'>{comments}</span>}
      <TestResult logs={logs} value={value} actions={actions} variable={variable} using_variables={using_variables} />
    </>
  );
}
function mapStateToProps(state) {
  return {
    codes: {
      ...state.code,
    },
  };
}
export default connect(mapStateToProps)(StrategyLog);
